package net.helix.engine.library.items;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.Sphere;

import net.helix.core.geometry.Geometry_Material;
import net.helix.element.Element;
import net.helix.element.Element_Material;
import net.helix.engine.Engine;
import net.helix.engine.library.Library;
import net.helix.engine.properties.Properties;
import net.helix.engine.properties.Properties_Material;

public class LibraryItem_Material extends LibraryItem {
	Geometry_Material material;
	public LibraryItem_Material(Library library, String name, Geometry_Material material) {
		super(library, name);
		this.type = LibraryItemType.MATERIAL;
		
		this.material = material;
	}
	/*
	public void setMaterial(Geometry_Material material){
		this.material = material;
	}
	 */
	@Override
	public void renderLibrary(Engine engine, int width, int height) {
		// TODO: Materials should show a sphere, cube, ect with the material applied
		// should not be possible... but
		material.applyProperties((Properties_Material) getDefaultPreset());
		
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GLU.gluPerspective(45, (float) width/(float) height, .1f, 100f);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();
		
		material.bind();
		
		GL11.glTranslatef(0, 0, -2f);
		GL11.glRotatef(90, 0, 1, 0);
		
		sphere.draw(.5f, 30, 30);
		
		material.unbind();
		
	}
	
	static Sphere sphere = new Sphere();
	static{
		sphere.setTextureFlag(true);
	}
	
	@Override
	public void render(Properties properties) {
		material.applyProperties((Properties_Material) properties);
		
		material.render();
		
	}

	@Override
	public Properties makeDefaultProperties() {
		return new Properties_Material();
	}

	@Override
	public Element createElement() {
		return new Element_Material(this);
	}

}
